package com.roundarchisobar.njariwala.netflix.dto;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.roundarchisobar.njariwala.netflix.dto.elements.BoxArt;
import com.roundarchisobar.njariwala.netflix.dto.elements.Link;
import com.roundarchisobar.njariwala.netflix.dto.elements.Title;

@XmlRootElement(name = "catalog_title")
public class NetflixCatalogTitle extends NetflixBaseEntity {

	private static final Logger logger = LoggerFactory.getLogger(NetflixCatalogTitle.class);

	private Title title;
	private BoxArt boxArt;
	private String id;
	private float averageRating;
	private long releaseYear;
	private List<Link> links;
	
	private String movieSeriesId;
	private String movieSeriesType;
	private String synopsis;

	@XmlElement(name = "title")
	public Title getTitle() {
		return title;
	}

	public void setTitle(Title title) {
		this.title = title;
	}

	@XmlElement(name = "box_art")
	public BoxArt getBoxArt() {
		return boxArt;
	}

	public void setBoxArt(BoxArt boxArt) {
		this.boxArt = boxArt;
	}

	@XmlElement(name = "id")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@XmlElement(name = "average_rating")
	public float getAverageRating() {
		return averageRating;
	}

	public void setAverageRating(float averageRating) {
		this.averageRating = averageRating;
	}
	
	
	@XmlElement(name = "release_year")
	public long getReleaseYear() {
		return releaseYear;
	}

	public void setReleaseYear(long releaseYear) {
		this.releaseYear = releaseYear;
	}

	@XmlElement(name = "link")
	public List<Link> getLinks() {
		return links;
	}

	public void setLinks(List<Link> links) {
		this.links = links;
	}

	public String getMovieSeriesId() {
		this.movieSeriesId = StringUtils.substringAfterLast(getId(), "/");
		return movieSeriesId;
	}

	public void setMovieSeriesId(String movieSeriesId) {
		this.movieSeriesId = movieSeriesId;
	}

	public String getMovieSeriesType() {
		String firstSubString = StringUtils.substringBeforeLast(getId(), "/");
		String secondSubString = StringUtils.substringAfterLast(firstSubString, "/");
		this.movieSeriesType = secondSubString;
		return movieSeriesType;
	}

	public void setMovieSeriesType(String movieSeriesType) {
		this.movieSeriesType = movieSeriesType;
	}

	public String getSynopsis() {
		return synopsis;
	}

	public void setSynopsis(String synopsis) {
		this.synopsis = StringUtils.substringBefore(StringUtils.substringAfter(synopsis,"<synopsis><![CDATA["),"]]></synopsis>");
	}

	
}
